﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpNewFeaturesUse
{
    public class Records
    {
        public record Person
        {
            public required string FirstName { get; init; }
            public required string LastName { get; init; }
            public required string[] PhoneNumbers { get; init; }
        }
        public static void ShowUse()
        {
            Console.WriteLine("用with关键字创建记录的副本，并改动其中部分属性");
            Person person1 = new Person { FirstName = "Nancy", LastName = "Davolio",  PhoneNumbers = new string[1] };
            Console.WriteLine(person1);
            // output: Person { FirstName = Nancy, LastName = Davolio, PhoneNumbers = System.String[] }

            Person person2 = person1 with { FirstName = "John" };
            Console.WriteLine(person2);
            // output: Person { FirstName = John, LastName = Davolio, PhoneNumbers = System.String[] }

            person2 = person1 with { LastName = "John" };
            Console.WriteLine(person2);
            // output: Person { FirstName = Nancy, LastName = John, PhoneNumbers = System.String[] }

            // record默认使用属性依次比较确定是否相等
            Console.WriteLine($"判断是否相等: {person1 == person2}"); // output: False

        }
    }
}